//
//  CMJBadgeButton.m
//  CMJWeibo
//
//  Created by BH on 15/12/3.
//
//

#import "CMJBadgeButton.h"
#import "UIImage+MJ.h"
#import "UIView+MJ.h"

@implementation CMJBadgeButton

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleLabel.font = [UIFont systemFontOfSize:10.f];
        
        [self setBackgroundImage:[UIImage resizableImage:@"main_badge"] forState:UIControlStateNormal];
        self.size = self.currentBackgroundImage.size;
        self.userInteractionEnabled = NO;
    }
    return self;
}

-(void)setBadgeValue:(NSString *)badgeValue
{
    _badgeValue = badgeValue;
    
    NSInteger badgeInt = badgeValue.integerValue;
    if (badgeInt == 0) {
        // 没有值可以显示
        self.hidden = YES;
    }else{
        self.hidden = NO;
        [self setTitle:badgeValue forState:UIControlStateNormal];
    }
}

@end
